package com.jz.community.moduleshopping.coupon.ui;

import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.flyco.tablayout.SlidingTabLayout;
import com.jz.community.basecomm.base.BaseHtml5Activity;
import com.jz.community.basecomm.base.BaseMvpActivity;
import com.jz.community.basecomm.base.BaseX5WebActivity;
import com.jz.community.basecomm.mvp.BaseMvpPresenter;
import com.jz.community.basecomm.routerUtils.RouterIntentConstant;
import com.jz.community.commview.commPagerAdapter.CommonViewPagerAdapter;
import com.jz.community.moduleshopping.R;
import com.jz.community.moduleshopping.R2;

import butterknife.BindView;

/**
 * Created by Tony.Fan on 2018/6/06 14:16
 *
 * 优惠券列表
 */
@Route(path = RouterIntentConstant.MODULE_SHOPPING_COUPON)
public class CouponListActivity extends BaseMvpActivity {
    @BindView(R2.id.coupon_list_back)
    ImageView couponListBack;
    @BindView(R2.id.coupon_list_title)
    TextView couponListTitle;
    @BindView(R2.id.coupon_list_find)
    TextView couponListFind;
    @BindView(R2.id.coupon_list_toolbar)
    Toolbar couponListToolbar;
    @BindView(R2.id.coupon_list_tab)
    SlidingTabLayout couponListTab;
    @BindView(R2.id.coupon_list_vp)
    ViewPager couponListVp;
    private String[] titles = {"可用", "历史"};

    @Override
    protected int getContentView() {
        return R.layout.module_shopping_activity_coupon_list;
    }

    @Override
    protected BaseMvpPresenter createPresenter() {
        return null;
    }


    @Override
    protected void initView() {
        setImmersionBar(couponListToolbar);
        couponListTitle.setText("我的优惠券");
        CommonViewPagerAdapter viewPagerAdapter = new CommonViewPagerAdapter(getSupportFragmentManager());
        for (int i = 0; i < titles.length; i++) {
            CouponListFragment firstFragment = CouponListFragment.newInstance(i);
            viewPagerAdapter.addFragment(firstFragment,i);
        }
        couponListVp.setOffscreenPageLimit(2);
        couponListVp.setAdapter(viewPagerAdapter);
        couponListTab.setViewPager(couponListVp, titles);

        couponListVp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }

            @Override
            public void onPageSelected(int position) {
                CouponListFragment.newInstance(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {
            }
        });
    }

    @Override
    protected void addListener() {
        couponListBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        couponListFind.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String base_url = "http://api2.shequren.cn/";
                String url = base_url + "/index.php?m=Home&c=Topic&a=index&id=15";
                toWebView(url, "优惠券说明");
            }
        });
    }

    private void toWebView(String webUrl, String title) {
        Intent intent = new Intent(this, BaseX5WebActivity.class);
        intent.putExtra("url", webUrl);
        intent.putExtra("title", title);
        startActivity(intent);
    }
}
